package com.example.administrator.demos;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;


import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class MainActivity extends AppCompatActivity {
    private List<Fruit> mfruits =new ArrayList<Fruit>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initFruits();
        RecyclerView recycler = (RecyclerView) findViewById(R.id.recycler_view);
        /*LinearLayoutManager manager = new LinearLayoutManager(this);
        manager.setOrientation(LinearLayoutManager.HORIZONTAL);*/
        //纵向瀑布流的实现
        StaggeredGridLayoutManager manager = new StaggeredGridLayoutManager(3,StaggeredGridLayoutManager.VERTICAL);
        recycler.setLayoutManager(manager);
        FruitAdapter fruit = new FruitAdapter(mfruits);
        recycler.setAdapter(fruit);
    }

    private void initFruits() {
        for (int i = 0 ; i <5; i++){
            Fruit fruit = new Fruit(getRandomNames("标清卡口"),R.mipmap.biao);
            mfruits.add(fruit);
            Fruit fruit2 = new Fruit(getRandomNames("高清卡口"),R.mipmap.gao);
            mfruits.add(fruit2);
            Fruit fruit3 = new Fruit(getRandomNames("普通卡口"),R.mipmap.kakou);
            mfruits.add(fruit3);
            Fruit fruit4 = new Fruit(getRandomNames("信号机"),R.mipmap.xinhao);
            mfruits.add(fruit4);

        }
    }

    private String getRandomNames(String name){
        Random random = new Random();
        int randomInt = random.nextInt(20) + 1;
        StringBuilder buider = new StringBuilder();
        for ( int i = 0 ; i <randomInt ; i++){
            buider.append(name);
        }
        return buider.toString();
    }
}
